/**
 * 
 */
package x.javax.activation;

import java.io.IOException;
import java.net.URI;

import x.java.io.File;

/**
 * @author qiangli
 *
 */
public class FileDataSource extends javax.activation.FileDataSource {
	private File file = null;
	public FileDataSource(File file) {
		super(getNativeFile(file));
		this.file = file;
	}

	public FileDataSource(String file) {
		this(new File(file));
	}

	@Override
	public File getFile() {
		return file;
	}

	private static java.io.File getNativeFile(File file) {
		try {
			URI uri = file.toRealURI();
			String p = uri.getScheme();
			if (!p.equals("file")) {
				uri = file.replicate().toURI();
			}
			return new java.io.File(uri);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
}
